home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / castools.zip / FREEPBE.C < prev    next >
Text File  |  1989-12-22  |  1KB  |  56 lines

  1.  
  2.  
  3. /*
  4.    FREEPBE.C  Function PbFreePBE: Frees the conventional memory used by
  5.       a phonebook entry function.
  6.  
  7.    INPUT:  Phonebook entry structure.  This structure must be in
  8.       conventional memory obtained from using the MSC functions malloc,
  9.       calloc, or realloc.
  10.  
  11.    OUTPUT: None, except if any of the pointers it should free are NULL, it
  12.             sets Pberrno to a warning.
  13. */
  14.  
  15. #include <stdio.h>
  16. #include <malloc.h>
  17. #include <phonebk.h>
  18.  
  19. void pascal PbFreePBE(PB *pb, PBE *entry)
  20. {
  21.   int i;
  22.  
  23.   Pberrno = 0;
  24.  
  25.   if (!entry || !pb) {
  26.     Pberrno = INVALIDPARAMETER;
  27.   }
  28.   else {
  29.     if (entry->type == PERSONENTRY) {
  30.       if (entry->fields) {
  31.         for (i=0; i<pb->header.fields; i++) {
  32.           if (entry->fields[i]) {
  33.             free(entry->fields[i]);
  34.           }
  35.           else {
  36.             Pberrno = NULLPOINTER;
  37.           }
  38.         }
  39.         free(entry->fields);
  40.       }
  41.       else {
  42.         Pberrno = NULLPOINTER;
  43.       }
  44.     }
  45.     if (entry->members) {
  46.       if (entry->MemberList) {
  47.         free(entry->MemberList);
  48.       }
  49.       else {
  50.         Pberrno = NULLPOINTER;
  51.       }
  52.     }
  53.     free(entry);
  54.   }
  55. }
  56.